package com.sls.nzdapplication.ui.activity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.media.ExifInterface;
import android.os.Bundle;
import android.os.Environment;
import android.text.Editable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

import com.bin.david.form.core.SmartTable;
import com.bin.david.form.data.column.Column;
import com.bin.david.form.data.style.FontStyle;
import com.bin.david.form.data.table.TableData;
import com.hjq.shape.view.ShapeRadioButton;
import com.hjq.widget.view.ClearEditText;
import com.hjq.widget.view.RegexEditText;
import com.hmy.popwindow.PopItemAction;
import com.hmy.popwindow.PopWindow;
import com.markfrain.formview.view.FormEditView;
import com.sls.nzdapplication.R;
import com.sls.nzdapplication.app.AppActivity;
import com.sls.nzdapplication.db.utils.EquipmentLineUtil;
import com.sls.nzdapplication.db.utils.EquipmentUtil;
import com.sls.nzdapplication.model.ByqInfo;
import com.sls.nzdapplication.model.Equipment;
import com.sls.nzdapplication.model.EquipmentLine;
import com.sls.nzdapplication.myapp.ZDAPP;
import com.sls.nzdapplication.ui.custom.CableWellPhotoView;
import com.sls.nzdapplication.util.DeviceUtils;
import com.sls.nzdapplication.util.LatlonUtil;
import com.sls.nzdapplication.util.Utils;
import com.sls.nzdapplication.util.UuidUtils;

import org.angmarch.views.NiceSpinner;
import org.angmarch.views.OnSpinnerItemSelectedListener;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import es.dmoral.toasty.Toasty;
import me.kareluo.ui.OptionMenu;
import me.kareluo.ui.OptionMenuView;
import me.kareluo.ui.PopupMenuView;

/**
 * 这个类是一个设备信息的Activity，主要用于设备信息的录入和展示。
 * */
public class EquipmentActivity extends AppActivity implements CableWellPhotoView.OnclickPhotoListener, View.OnClickListener {
    NiceSpinner dxxhView,typeView,dxlxView,ljfsView,sbztView,gtxzView,gtczView,gtxhView,tgjsView,jcxsView,sbrlView,kgztView,byqslView;
    TextView latView,lonView;
    RadioGroup sfnwView;
    ImageView qxxxRight,qdsbRight,ssgtRight,addbyq;
    TableRow qxxxInfoView,sbztInfoView,sbrlInfoView,kgztInfoView,dzInfoView,qdsbInfoView;
    LinearLayout dxgInfoView;
    SmartTable byqTable;
    private ClearEditText qxxxView,qssbView,ssgtView;
    TextView saveEquipmentView;
    private CableWellPhotoView equipmentQmPhotoView;

    private CableWellPhotoView equipmentMpPhotoView;

    private CableWellPhotoView equipmentGpPhotoView;

    private CableWellPhotoView equipmentQxPhotoView;

    private CableWellPhotoView equipmentTtPhotoView;

    private String photoType;

    private String selectGtid;

    private List<Equipment> equipmentList;

    private int selectE = 0;

    PopWindow popupWindow;


    private LinearLayout byqInfoView;


    private int code = 0;

    private Equipment exEquipment;

    private AutoCompleteTextView autoCompleteTextViewNameView;

    ShapeRadioButton sfnwOkView,sfnwNoView;

    private String equipmentId;

    private String type;

    private String clickEquipmentId = "";

    private EquipmentUtil equipmentUtil;

    private boolean isNew = true;

    private String lineId = "";

    private EquipmentLineUtil equipmentLineUtil;

    private Double lat = 0.0;

    private Double lon = 0.0;

    private CableWellPhotoView equipmentGpsPhotoView;

    private CableWellPhotoView equipmentZsqPhotoView;

    private CableWellPhotoView equipmentBlqPhotoView;


    static final List<String> tgjsList = new ArrayList<>();
    static {
        tgjsList.add("0");
        tgjsList.add("1");
        tgjsList.add("2");
        tgjsList.add("3");
        tgjsList.add("4");}

    static final List<String> gtxzList = new ArrayList<>();
    static {

        gtxzList.add("直线");
        gtxzList.add("耐张");
    }

    static final List<String> gtczList = new ArrayList<>();
    static {
        gtczList.add("水泥杆");
        gtczList.add("角杆塔");
        gtczList.add("钢管塔");
        gtczList.add("钢管杆");
        gtczList.add("其他");
    }

    static final List<String> gtlxList = new ArrayList<>();
    static {
        gtlxList.add("水泥杆10米");
        gtlxList.add("水泥杆11米");
        gtlxList.add("水泥杆12米");
        gtlxList.add("水泥杆13米");
        gtlxList.add("水泥杆12.5米");
        gtlxList.add("水泥杆15米");
        gtlxList.add("水泥杆16米");
        gtlxList.add("水泥杆19米");
        gtlxList.add("水泥杆21米");
        gtlxList.add("钢杆10");
        gtlxList.add("钢杆12");
        gtlxList.add("钢杆12.5");
        gtlxList.add("钢杆13.5");
        gtlxList.add("钢杆15");
        gtlxList.add("钢杆16");
        gtlxList.add("钢杆18");
        gtlxList.add("钢杆19");
        gtlxList.add("钢杆21.5");
    }

    static final List<String> jcxsList = new ArrayList<>();
    static {
        jcxsList.add("水泥杆基础");
        jcxsList.add("钢筋混凝土");
        jcxsList.add("掏挖基础");
        jcxsList.add("灌注桩基础");
        jcxsList.add("嵌入式");
        jcxsList.add("素混");
        jcxsList.add("其他");
    }

    static final List<String> dxxhList = new ArrayList<>();
    static {
        dxxhList.add("JKLGV-120");
        dxxhList.add("JKLGV-35");
        dxxhList.add("JKLGV-50");
        dxxhList.add("JKLGYJ-120");
        dxxhList.add("JKLGYJ-120/20");
        dxxhList.add("JKLGYJ-120/25");
        dxxhList.add("JKLGYJ-120/7");
        dxxhList.add("JKLGYJ-150");
        dxxhList.add("JKLGYJ-150/10");
        dxxhList.add("JKLGYJ-150/25");
        dxxhList.add("JKLGYJ-185");
        dxxhList.add("JKLGYJ-185/25");
        dxxhList.add("JKLGYJ-240");
        dxxhList.add("JKLGYJ-240/10");
        dxxhList.add("JKLGYJ-240/40");
        dxxhList.add("JKLGYJ-25");
        dxxhList.add("JKLGYJ-35");
        dxxhList.add("JKLGYJ-35/6");
        dxxhList.add("JKLGYJ-50");
        dxxhList.add("JKLGYJ-50/10");
        dxxhList.add("JKLGYJ-50/8");
        dxxhList.add("JKLGYJ-70");
        dxxhList.add("JKLGYJ-70/10");
        dxxhList.add("JKLGYJ-95");
        dxxhList.add("JKLGYJ-95/10");
        dxxhList.add("JKLGYJ-95/15");
        dxxhList.add("JKLHYJ/Q-10/240");
        dxxhList.add("JKLHYJ/Q-10/70");
        dxxhList.add("JKLJ-120");
        dxxhList.add("JKLV-185");
        dxxhList.add("JKLV-35");
        dxxhList.add("JKLYJ/Q-185");
        dxxhList.add("JKLYJ-10/150");
        dxxhList.add("JKLYJ-120");
        dxxhList.add("JKLYJ-125");
        dxxhList.add("JKLYJ-150");
        dxxhList.add("JKLYJ-150/10");
        dxxhList.add("JKLYJ-165");

        dxxhList.add("JKLYJ-185");
        dxxhList.add("JKLYJ-210");
        dxxhList.add("JKLYJ-240");
        dxxhList.add("JKLYJ-240/10");
        dxxhList.add("JKLYJ-25");
        dxxhList.add("JKLYJ-300");
        dxxhList.add("JKLYJ-35");
        dxxhList.add("JKLYJ-400");
        dxxhList.add("JKLYJ-50");
        dxxhList.add("JKLYJ-50/10");
        dxxhList.add("JKLYJ-500");
        dxxhList.add("JKLYJ-70");
        dxxhList.add("JKLYJ-75");
        dxxhList.add("JKLYJ-90");
        dxxhList.add("JKLYJ-95");
        dxxhList.add("JKLYJ-95/10");

        dxxhList.add("JKTRYJ-120");
        dxxhList.add("JKTRYJ-25");
        dxxhList.add("JKTRYJ-35");
        dxxhList.add("LGJ-10/120");
        dxxhList.add("LGJ-120");
        dxxhList.add("LGJ-150");
        dxxhList.add("LGJ-240");
        dxxhList.add("LGJ-240/40");
        dxxhList.add("LGJ-25/5");
        dxxhList.add("LGJ-35/5");
        dxxhList.add("LGJ-70");
        dxxhList.add("LGJ-90");
    }
    static final List<String> dydxxhList = new ArrayList<>();
    static {
        dydxxhList.add("YJV22-3x50");
        dydxxhList.add("YJV22-3x95");
        dydxxhList.add("YJV22-3x120");
        dydxxhList.add("YJV22-3x150");
        dydxxhList.add("YJV22-3x185");
        dydxxhList.add("YJV22-3x240");
        dydxxhList.add("YJV22-3x300");

        dydxxhList.add("YJLV22-3×50");
        dydxxhList.add("YJLV22-3×70");
        dydxxhList.add("YJLV22-3×95");
        dydxxhList.add("YJLV22-3×150");
        dydxxhList.add("YJLV22-3×300");
        dydxxhList.add("YJLV22-3×400");
    }

    static final List<String> sbrlList = new ArrayList<>();
    static {
        sbrlList.add("1250");
        sbrlList.add("1000");
        sbrlList.add("630");
        sbrlList.add("500");
        sbrlList.add("400");
        sbrlList.add("315");
        sbrlList.add("250");
        sbrlList.add("200");
        sbrlList.add("160");
        sbrlList.add("125");
        sbrlList.add("100");
        sbrlList.add("80");
        sbrlList.add("50");
        sbrlList.add("30");
    }

    static final List<String> kgztList = new ArrayList<>();
    static {
        kgztList.add("闭合");
        kgztList.add("拉开");}

    static final List<String> byqslList = new ArrayList<>();
    static {
        byqslList.add("1");
        byqslList.add("2");
        byqslList.add("3");
        byqslList.add("4");
        byqslList.add("5");
        byqslList.add("6");
        byqslList.add("7");
        byqslList.add("8");
        byqslList.add("9");
        byqslList.add("10");
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_equipment;
    }

    @Override
    protected void initView() {
        autoCompleteTextViewNameView = findViewById(R.id.equipment_name);
        dxxhView = (NiceSpinner) findViewById(R.id.dy_equipment_dxxh);
        dxxhView.attachDataSource(dxxhList);
        typeView = (NiceSpinner) findViewById(R.id.dy_equipment_type);
        dxlxView = (NiceSpinner) findViewById(R.id.dy_equipment_dxlx);
        List<String> projName3 = new ArrayList<>();
        projName3.add("绝缘");
        projName3.add("电缆");
        projName3.add("裸线");
        dxlxView.attachDataSource(projName3);

        dxlxView.setOnSpinnerItemSelectedListener(new OnSpinnerItemSelectedListener() {
            @Override
            public void onItemSelected(NiceSpinner parent, View view, int position, long id) {
                if(position == 1){
                    dxxhView.attachDataSource(dydxxhList);
                }else{
                    dxxhView.attachDataSource(dxxhList);
                }
            }
        });
        ljfsView = (NiceSpinner) findViewById(R.id.dy_equipment_ljfs);
        List<String> projName4 = new ArrayList<>();
        projName4.add("架空");
        projName4.add("入地");
        ljfsView.attachDataSource(projName4);
        sbztView = (NiceSpinner) findViewById(R.id.dy_equipment_sbzt);
        List<String> projName5 = new ArrayList<>();
        projName5.add("在运");
        projName5.add("停运");
        projName5.add("未投运");
        sbztView.attachDataSource(projName5);

        qssbView = findViewById(R.id.equipment_qdsb);
        qssbView.setFocusable(false);
        gtxzView = findViewById(R.id.dy_equipment_gtxz);
        gtxzView.attachDataSource(gtxzList);
        gtczView = findViewById(R.id.dy_equipment_gtcl);
        gtczView.attachDataSource(gtczList);
        gtxhView = findViewById(R.id.dy_equipment_gtxh);
        gtxhView.attachDataSource(gtlxList);
        tgjsView = findViewById(R.id.dy_equipment_tgjs);
        tgjsView.attachDataSource(tgjsList);
        jcxsView = findViewById(R.id.dy_equipment_jcxs);
        jcxsView.attachDataSource(jcxsList);
        ssgtView = findViewById(R.id.equipment_ssgt);

        latView = findViewById(R.id.equipment_lat);
        lonView = findViewById(R.id.equipment_lon);
        sfnwView = findViewById(R.id.dy_equipment_sfnw);
        qxxxRight = findViewById(R.id.qxxx_right);
        qdsbRight = findViewById(R.id.qdsb_right);

        qxxxInfoView = findViewById(R.id.qxxx_info_view);
        sbztInfoView = findViewById(R.id.sbzt_info_view);
        sbrlInfoView = findViewById(R.id.sbrl_view);
        kgztInfoView = findViewById(R.id.kgzt_view);
        qdsbInfoView = findViewById(R.id.qdsb_info_view);
        byqInfoView = findViewById(R.id.byqsl_info_view);
        dzInfoView = findViewById(R.id.dz_view);

        byqslView = findViewById(R.id.equipment_byqsl);
        byqslView.attachDataSource(byqslList);

        addbyq = findViewById(R.id.add_byq);
        qxxxView = findViewById(R.id.equipment_qxxx);
        dxgInfoView = findViewById(R.id.dxg_view);
        sfnwOkView = findViewById(R.id.snfw_ok);
        sfnwNoView = findViewById(R.id.snfw_no);

        sbrlView = findViewById(R.id.zy_equipment_sbrl);
        sbrlView.attachDataSource(sbrlList);

        kgztView = findViewById(R.id.equipment_kgzt);
        kgztView.attachDataSource(kgztList);

        saveEquipmentView = findViewById(R.id.save_equipment);
        saveEquipmentView.setOnClickListener(this);

        byqTable = findViewById(R.id.byq_table);
        byqTable.getConfig().setShowXSequence(false);
        byqTable.getConfig().setShowYSequence(false);
        byqTable.getConfig().setShowTableTitle(false);
        byqTable.getConfig().setColumnTitleStyle (new FontStyle(30, getResources().getColor(R.color.colorPrimaryDark)));
        byqTable.getConfig().setMinTableWidth(getActivity().getWindowManager().getDefaultDisplay().getWidth());

        equipmentQmPhotoView = findViewById(R.id.equipment_qm_photo);
        equipmentQmPhotoView.setOnclickPhotoListener(this);


        equipmentMpPhotoView = findViewById(R.id.equipment_mp_photo);
        equipmentMpPhotoView.setOnclickPhotoListener(this);

        equipmentGpPhotoView = findViewById(R.id.equipment_gp_photo);
        equipmentGpPhotoView.setOnclickPhotoListener(this);

        equipmentQxPhotoView = findViewById(R.id.equipment_qx_photo);
        equipmentQxPhotoView.setOnclickPhotoListener(this);

        equipmentTtPhotoView = findViewById(R.id.equipment_tt_photo);
        equipmentTtPhotoView.setOnclickPhotoListener(this);

        equipmentGpsPhotoView  = findViewById(R.id.equipment_gps_photo);
        equipmentGpsPhotoView.setOnclickPhotoListener(this);

        equipmentZsqPhotoView = findViewById(R.id.equipment_zsq_photo);
        equipmentZsqPhotoView.setOnclickPhotoListener(this);

        equipmentBlqPhotoView = findViewById(R.id.equipment_blq_photo);
        equipmentBlqPhotoView.setOnclickPhotoListener(this);
        qxxxRight.setOnClickListener(this);
        qdsbRight.setOnClickListener(this);
        equipmentUtil = new EquipmentUtil(getApplicationContext());
        equipmentLineUtil = new EquipmentLineUtil(getApplicationContext());

        ssgtRight = findViewById(R.id.ssgt_right);
        ssgtRight.setOnClickListener(this);

        addbyq.setOnClickListener(this);
    }

    private void initType(){
        List<String> types = new ArrayList<>();
        if(type.equals(ZDAPP.EQUIPMENT_BDZ)){
            types.add("变电站");
        }
        else if(type.equals(ZDAPP.EQUIPMENT_DXG)){
            types.add("杆塔");
        }
        else if(type.equals(ZDAPP.EQUIPMENT_DLQ)){
            types.add("柱上负荷开关");
            types.add("断路器");
            types.add("隔离开关");
        }
        else if(type.equals(ZDAPP.EQUIPMENT_DZ)){
            types.add("环网柜");
            types.add("分支箱");
            types.add("开关站");
            types.add("开闭所");
            types.add("配电室");
        }
        else if(type.equals(ZDAPP.EQUIPMENT_GYB)){
            types.add("公用配电变压器");
            types.add("公用柱上变压器");
            types.add("用户专变");
        }else{
            types.add("跌落式熔断器");
        }
        typeView.attachDataSource(types);
        typeView.setOnSpinnerItemSelectedListener(new OnSpinnerItemSelectedListener() {
            @Override
            public void onItemSelected(NiceSpinner parent, View view, int position, long id) {

                if(position == 4 && type.equals(ZDAPP.EQUIPMENT_DZ)){
                    equipmentQxPhotoView.setVisibility(View.GONE);
                    equipmentGpPhotoView.setVisibility(View.GONE);
                    byqInfoView.setVisibility(View.VISIBLE);
                    byqTable.setVisibility(View.VISIBLE);
                }else if(position != 4 && type.equals(ZDAPP.EQUIPMENT_DZ)){
                    byqInfoView.setVisibility(View.GONE);
                    equipmentQxPhotoView.setVisibility(View.VISIBLE);
                    equipmentGpPhotoView.setVisibility(View.VISIBLE);
                    byqTable.setVisibility(View.GONE);
                }
            }
        });
    }

    @Override
    protected void initData() {
        Intent intent = getIntent();
        if(null !=intent && intent.getStringExtra("equipmentId")!=null){
            isNew = false;
            equipmentId = intent.getStringExtra("equipmentId");
            Equipment equipment = equipmentUtil.listOneEquipment(equipmentId);
            autoCompleteTextViewNameView.setText(equipment.getName());
            typeView.setText(equipment.getType());
            latView.setText(String.valueOf(equipment.getLat()));
            lonView.setText(String.valueOf(equipment.getLon()));
            dxlxView.setText(equipment.getDxlx()==null?"":equipment.getDxlx());
            dxxhView.setText(equipment.getDlxh()==null?"":equipment.getDlxh());
            ljfsView.setText(equipment.getLxfs()==null?"":equipment.getLxfs());
            qxxxView.setText(equipment.getQxxx()==null?"":equipment.getQxxx());
            sbztView.setText(equipment.getSbzt()==null?"":equipment.getSbzt());
            gtczView.setText(equipment.getGtcz()==null?"":equipment.getGtcz());
            gtxzView.setText(equipment.getGtxz()==null?"":equipment.getGtxz());
            gtxhView.setText(equipment.getGtxh()==null?"":equipment.getGtxh());
            jcxsView.setText(equipment.getJcxs()==null?"":equipment.getJcxs());
            sbrlView.setText(equipment.getSbrl()==null?"":equipment.getSbrl());
            kgztView.setText(equipment.getKgzt()==null?"":equipment.getKgzt());
            tgjsView.setText(equipment.getTgjs()==null?"":equipment.getTgjs());
            code = equipment.getCode();
            if(equipment.getSsgt()!=null && !equipment.getSsgt().equals("")){
                EquipmentUtil equipmentUtil = new EquipmentUtil(getApplicationContext());
                Equipment ssgtequipment = equipmentUtil.listOneEquipment(equipment.getSsgt());
                if(ssgtequipment!=null){
                    ssgtView.setText(ssgtequipment.getName());
                    selectGtid = equipment.getSsgt()==null?"":equipment.getSsgt();
                }else{
                    selectGtid = "";
                }
            }
            if(equipment.getSfnw()!=null && equipment.getSfnw().equals("是")){
                sfnwOkView.setChecked(true);
            }else{
                sfnwNoView.setChecked(true);
            }
            type = equipment.getType();
            lineId = equipment.getWorkLineId();

            if(!type.equals("变电站")){
                Equipment ex = equipmentUtil.listOneEquipment(equipment.getPreviousEquipmentId());
                if(ex!=null){
                    qssbView.setText(ex.getName());
                    clickEquipmentId = equipment.getPreviousEquipmentId();
                }
            }else{
                qssbView.setVisibility(View.GONE);
                equipmentTtPhotoView.setVisibility(View.GONE);
                equipmentQxPhotoView.setVisibility(View.GONE);
                equipmentGpPhotoView.setVisibility(View.GONE);
            }
            if(ZDAPP.kgType.contains(type)){
                kgztInfoView.setVisibility(View.VISIBLE);
                dzInfoView.setVisibility(View.VISIBLE);
            }
            if(type.equals("杆塔")){
                dxgInfoView.setVisibility(View.VISIBLE);
                equipmentTtPhotoView.setVisibility(View.VISIBLE);
                equipmentGpsPhotoView.setVisibility(View.VISIBLE);
                equipmentZsqPhotoView.setVisibility(View.VISIBLE);
                equipmentBlqPhotoView.setVisibility(View.VISIBLE);
            }
            if(ZDAPP.eqType.contains(type)){
//                dzLayout.setVisibility(View.VISIBLE);
            }
            if(ZDAPP.gybType.contains(type)){
                sbrlInfoView.setVisibility(View.VISIBLE);
                dzInfoView.setVisibility(View.VISIBLE);
            }
            if(type.equals("配电室")){
                byqInfoView.setVisibility(View.VISIBLE);
                byqTable.setVisibility(View.VISIBLE);
                equipmentQxPhotoView.setVisibility(View.GONE);
                equipmentGpPhotoView.setVisibility(View.GONE);
                showDataView();
            }

        }
        else if(null !=intent && intent.getBundleExtra("params") != null){
            Bundle bundle = intent.getBundleExtra("params");
            lat = bundle.getDouble("lat");
            lon = bundle.getDouble("lon");
            type = bundle.getString("type");
            lineId = bundle.getString("lineId");
            clickEquipmentId = bundle.getString("clickE");
            equipmentId = UuidUtils.getStringID();
            latView.setText(String.valueOf(lat));
            lonView.setText(String.valueOf(lon));
            dxlxView.setText("绝缘");
            sbztView.setText("在运");
            ljfsView.setText("架空");
            sfnwOkView.setChecked(true);
            Equipment ex = null;
            if(!type.equals("变电站")){
                ex = equipmentUtil.listOneEquipment(clickEquipmentId);
                qssbView.setText(ex.getName());

            }else{
                qdsbInfoView.setVisibility(View.GONE);
                typeView.setText(type);
                equipmentTtPhotoView.setVisibility(View.GONE);
                equipmentQxPhotoView.setVisibility(View.GONE);
                equipmentGpPhotoView.setVisibility(View.GONE);
            }
            if(type.equals("开关")){
                kgztInfoView.setVisibility(View.VISIBLE);
                dzInfoView.setVisibility(View.VISIBLE);
                if(equipmentUtil.queryEquipmentByLineIdAndKg(lineId).size()==0){
                    code = 1;
                }else{
                    Equipment dye = equipmentUtil.queryEquipmentByLineIdAndKg(lineId).get(0);
                    code = dye.getCode()+1;
                }

                String myName = customName(ex.getType(),type,ex.getName(),ex.getId());
                autoCompleteTextViewNameView.setText(myName);
                autoCompleteTextViewNameView.setSelection(myName.length());

            }
            if(type.equals("杆塔")){
                typeView.setText(type);
                ljfsView.setText("架空");
                gtxzView.setText("直线");
                gtczView.setText("水泥杆");
                gtxhView.setText("水泥杆10米");
                jcxsView.setText("水泥杆基础");
                tgjsView.setText("0");
                dxgInfoView.setVisibility(View.VISIBLE);
                equipmentTtPhotoView.setVisibility(View.VISIBLE);
                equipmentGpsPhotoView.setVisibility(View.VISIBLE);
                equipmentZsqPhotoView.setVisibility(View.VISIBLE);
                equipmentBlqPhotoView.setVisibility(View.VISIBLE);
                List<Equipment> equipmentList = equipmentUtil.queryEquipmentByLineIdAndGt(lineId);
                if(equipmentList.size()==0){
                    code = 0;
                }else{
                    Equipment dye = equipmentList.get(equipmentList.size()-1);
                    code = dye.getCode()+1;
                }
                List<Equipment> gtlists = equipmentUtil.queryEquipmentByLineIdAndGt(lineId);
                if(gtlists.size()>0){
                    String gtname = gtlists.get(gtlists.size()-1).getName();
                    int l = 0;
                    char[] gtnames = gtname.toCharArray();
                    for(int i = gtnames.length;i>0;i--){
                        if(!isNumber(String.valueOf(gtnames[i-1]))){
                            l=i;
                            break;
                        }
                    }
                    if(l==gtname.length()){
                        autoCompleteTextViewNameView.setText(gtname+ Utils.getName(code));
                    }
                    else if(l!=gtname.length()-3 && l<gtname.length()){
                        autoCompleteTextViewNameView.setText(gtname.substring(0,l)+ (code));
                    }else{
                        autoCompleteTextViewNameView.setText(gtname.substring(0,gtname.length()-3)+ Utils.getName(code));
                    }
                }else{
                    autoCompleteTextViewNameView.setText("中压杆塔"+ Utils.getName(code));
                }
            }
            if(type.equals("跌落式熔断器")){
                typeView.setText(type);
                List<Equipment> equipmentList = equipmentUtil.queryEquipmentByLineIdAndKg(lineId);
                if(equipmentList.size()==0){
                    code = 1;
                }else{
                    Equipment dye = equipmentList.get(equipmentList.size()-1);
                    if(type.equals("杆塔")){
                        code = dye.getCode()+1;
                    }else{
                        code = dye.getCode();
                    }
                }
                String myName = customName(ex.getType(),type,ex.getName(),ex.getId());
                autoCompleteTextViewNameView.setText(myName);
                autoCompleteTextViewNameView.setSelection(myName.length());
            }
            if(type.equals("电站")){
                List<Equipment> equipmentList = equipmentUtil.queryEquipmentByLineIdAndDz(lineId);
                if(equipmentList.size()==0){
                    code = 1;
                }else{
                    Equipment dye = equipmentList.get(equipmentList.size()-1);
                    code = dye.getCode()+1;
                }
                String myName = customName(ex.getType(),type,ex.getName(),ex.getId());
                autoCompleteTextViewNameView.setText(myName);
                autoCompleteTextViewNameView.setSelection(myName.length());


            }
            if(type.equals("公用变")){
                sbrlInfoView.setVisibility(View.VISIBLE);
                List<Equipment> equipmentList = equipmentUtil.queryEquipmentByLineIdAndGyb(lineId);
                if(equipmentList.size()==0){
                    code = 1;
                }else{
                    Equipment dye = equipmentList.get(equipmentList.size()-1);
                    code = dye.getCode()+1;
                }
                String myName = customName(ex.getType(),type,ex.getName(),ex.getId());
                autoCompleteTextViewNameView.setText(myName);
                autoCompleteTextViewNameView.setSelection(myName.length());
            }
        }
        initType();
        equipmentQmPhotoView.initData("Equipment",equipmentId,"qm");
        equipmentMpPhotoView.initData("Equipment",equipmentId,"mp");
        equipmentTtPhotoView.initData("Equipment",equipmentId,"tt");
        equipmentGpPhotoView.initData("Equipment",equipmentId,"gp");
        equipmentQxPhotoView.initData("Equipment",equipmentId,"qx");
        equipmentGpsPhotoView.initData("Equipment",equipmentId,"gps");
        equipmentZsqPhotoView.initData("Equipment",equipmentId,"zsq");
        equipmentBlqPhotoView.initData("Equipment",equipmentId,"blq");
    }

    private boolean isNumber(String str){
        try {
            Integer.parseInt(str);
            return true;
        } catch(Exception e){
            return false;
        }
    }

    private int getcode(String name){
        String code = name.substring(name.length()-3,name.length());
        if(isNumber(code)){
            return Integer.parseInt(code)+1;
        }
        return 0;
    }

    private String typeName(String type){
        switch (type){
            case "环网柜":
            case "分支箱":
            case "开关站":
            case "开闭所":
            case "配电室":
                return "电站";
            case "柱上负荷开关":
            case "断路器":
            case "隔离开关":
                return "开关";
            case "公用配电变压器":
            case "公用柱上变压器":
            case "用户专变":
                return "公用变";
        }
        return type;
    }


    private Equipment getexEq(String type ,String exid){
        Equipment equipment = equipmentUtil.listOneEquipment(exid);
        if(!typeName(equipment.getType()).equals(typeName(type))){
            return equipment;
        }else{
            return getexEq(equipment.getType(),equipment.getPreviousEquipmentId());
        }
    }

    private int bigCode(String type ,String exid){
        Equipment equipment = getexEq(type ,exid);
        return getbigcode(equipment.getId(),type);
    }

    private  int getbigcode(String exid,String type){
        List<Equipment> equipmentList = equipmentUtil.queryEquipmentByAreaIdAndexqIdAndType(lineId,exid,type);
        List<String> stringList = new ArrayList<>();
        for(Equipment equipment1:equipmentList){
            stringList.addAll(getallName(new ArrayList<>(),equipment1));
        }
        int i = -1;
        for(String s:stringList){
            char[] namelist = s.toCharArray();
            int l = 0;
            for(int j = namelist.length;j>0;j--){
                if(!isNumber(String.valueOf(namelist[j-1]))){
                    l=j;
                    break;
                }
            }
            if(isNumber(s.substring(l,s.length()))){
                int n = Integer.parseInt(s.substring(l,s.length()));
                if(n>i){
                    i = n;
                }
            }
        }
        return i;
    }

    private List<String> getallName(List<String> list,Equipment equipment){
        List<String>  list1 = list;
        list1.add(equipment.getName());
        List<Equipment> equipmentList = equipmentUtil.queryEquipmentByAreaIdAndexqIdAndType(lineId,equipment.getId(),typeName(equipment.getType()));
        for(Equipment equipment1:equipmentList){
            if(typeName(equipment1.getType()).equals(typeName(equipment.getType()))){
                list1.addAll(getallName(list1,equipment1));
            }
        }
        return list1;
    }

    private String customName(String exType,String type ,String exname,String exid){
        String myName = "";
        exType = typeName(exType);
        if(exType.equals(type)){

            char[] namelist = exname.toCharArray();
            int l = 0;
            for(int i = namelist.length;i>0;i--){
                if(!isNumber(String.valueOf(namelist[i-1]))){
                    l=i;
                    break;
                }
            }
            if(l == exname.length()){
                myName = exname+ Utils.getName(bigCode(type,exid)+1);
            }
            else if(l!=exname.length()-3 && l<exname.length()){
                myName = exname.substring(0,l)+(bigCode(type,exid)+1);
            }else{
                myName = exname.substring(0,exname.length()-3)+Utils.getName(bigCode(type,exid)+1);
            }

        }else{
            myName = exname+typeName(type)+Utils.getName(getbigcode(exid,type)+1);
        }
        return myName;
    }

    private void saveData(){
        Equipment equipment;
        Editable name = autoCompleteTextViewNameView.getText();
        if(name == null || name.toString().equals("")){
            Toasty.error(getApplicationContext(), "设备名称不能为空", Toast.LENGTH_LONG, true).show();
            return;
        }
//        if(!isNumber(name.substring(name.length()-1,name.length())) && !type.equals("变电站")){
//            Toasty.error(getApplicationContext(), "设备名称命名不规范", Toast.LENGTH_LONG, true).show();
//            return;
//        }
        if((equipmentUtil.queryEquipmentByLineIdAndName(lineId,name.toString()).size()>0 && isNew) || (equipmentUtil.queryEquipmentByLineIdAndName(lineId,name.toString()).size()>0 && !equipmentUtil.queryEquipmentByLineIdAndName(lineId,name.toString()).get(0).getId().equals(equipmentId))){
            Toasty.error(getApplicationContext(), "设备已存在", Toast.LENGTH_LONG, true).show();
            return;
        }
        if(typeView.getText().toString().equals("")){
            Toasty.error(getApplicationContext(), "设备类型不能为空", Toast.LENGTH_LONG, true).show();
            return;
        }
        if(isNew){
            equipment = new Equipment();
        }else{
            equipment = equipmentUtil.listOneEquipment(equipmentId);
        }

        equipment.setId(equipmentId);
        equipment.setName(name.toString());
        equipment.setLon(Double.valueOf(lonView.getText().toString()));
        equipment.setLat(Double.valueOf(latView.getText().toString()));
        equipment.setType(typeView.getText().toString());
        if(!isNew && equipment.getPdxId() == null){
            if(!clickEquipmentId.equals(equipment.getPreviousEquipmentId())){
                List<EquipmentLine> equipmentLines = equipmentLineUtil.queryEquipmentLineByStartAndEnd(equipment.getPreviousEquipmentId(),equipmentId);
                for(EquipmentLine equipmentLine:equipmentLines){
                    equipmentLineUtil.deleteEquipmentLine(equipmentLine);
                }
                EquipmentLine equipmentLine = new EquipmentLine();
                equipmentLine.setId(UuidUtils.getStringID());
                equipmentLine.setStartEquipmentId(clickEquipmentId);
                equipmentLine.setEndEquipmentId(equipmentId);
                equipmentLine.setType("1");
                equipmentLine.setLineId(lineId);
                equipmentLineUtil.insertEquipmentLine(equipmentLine);
            }
        }
        equipment.setPreviousEquipmentId(clickEquipmentId);
        equipment.setDxlx(dxlxView.getText().toString());
        equipment.setDlxh(dxxhView.getText().toString());
        equipment.setLxfs(ljfsView.getText().toString());
        equipment.setQxxx(qxxxView.getText()==null?"":qxxxView.getText().toString());
        equipment.setSbzt(sbztView.getText().toString());
        if(type.equals("杆塔")){
            equipment.setGtxh(gtxhView.getText().toString());
            equipment.setGtcz(gtczView.getText().toString());
            equipment.setGtxz(gtxzView.getText().toString());
            equipment.setTgjs(tgjsView.getText().toString());
            equipment.setJcxs(jcxsView.getText().toString());
        }

        equipment.setSbrl(sbrlView.getText().toString());
        equipment.setKgzt(kgztView.getText().toString());
        equipment.setCode(code);
        if(((ShapeRadioButton) findViewById(sfnwView.getCheckedRadioButtonId())).getText().toString().equals("是")){
            equipment.setSfnw("是");
        }else{
            equipment.setSfnw("否");
        }
        equipment.setSsgt(selectGtid);
        equipment.setCreateTime(new Date());
        equipment.setWorkLineId(lineId);
        if(isNew){
            equipmentUtil.insertEquipment(equipment);
            if(!type.equals("变电站")){
                EquipmentLine equipmentLine = new EquipmentLine();
                equipmentLine.setId(UuidUtils.getStringID());
                equipmentLine.setStartEquipmentId(clickEquipmentId);
                equipmentLine.setEndEquipmentId(equipmentId);
                equipmentLine.setType("1");
                equipmentLine.setLineId(lineId);
                equipmentLineUtil.insertEquipmentLine(equipmentLine);
            }
        }else{
            equipmentUtil.updateEquipment(equipment);
        }
        Toasty.success(getApplicationContext(), "保存成功", Toast.LENGTH_LONG, true).show();
        isNew = false;
    }

    private void newByq(int number){
        Equipment byq = equipmentUtil.listOneEquipment(equipmentId);
        if(byq == null){
            Toasty.info(getApplicationContext(),"请先保存配电室",Toast.LENGTH_LONG, true).show();
            return;
        }
        List<Equipment> byqs = equipmentUtil.queryEquipmentByLineIdAndPDX(equipmentId);
        if(byqs.size()>0){
            Toasty.info(getApplicationContext(),"已存在变压器",Toast.LENGTH_LONG, true).show();
            return;
        }
        for(int i = 0;i<number;i++){
            Equipment equipment = new Equipment();
            equipment.setId(UuidUtils.getStringID());
            equipment.setName(byq.getName()+"变压器"+Utils.getName(i+1));
            equipment.setType("公用配电变压器");
            equipment.setPdxId(equipmentId);
            equipment.setWorkLineId(byq.getWorkLineId());
            equipment.setLat(byq.getLat());
            equipment.setLxfs("架空");
            equipment.setDxlx("绝缘");
            equipment.setSbzt("在运");
            equipment.setLon(byq.getLon());
            equipmentUtil.insertEquipment(equipment);
        }
        showDataView();
    }



    private void initGT(){
        List<String> gtName = new ArrayList<>();
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,300);
        ListView listView = new ListView(getApplicationContext());
        listView.setLayoutParams(layoutParams);
        EquipmentUtil equipmentUtil = new EquipmentUtil(getApplicationContext());
        List<Equipment> gtlist = equipmentUtil.queryEquipmentByLineIdAndGt(lineId);
        for(Equipment gt:gtlist){
            gtName.add(gt.getName());
        }
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Equipment equipment = gtlist.get(i);
                ssgtView.setText(equipment.getName());
                selectGtid = equipment.getId();
            }
        });
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                getApplicationContext(), android.R.layout.simple_list_item_1, gtName);
        listView.setAdapter(adapter);

        new PopWindow.Builder(this)
                .setStyle(PopWindow.PopWindowStyle.PopAlert)
                .setMessage("请选择杆塔")
                .addContentView(listView)
                .setIsShowCircleBackground(false)
                .addItemAction(new PopItemAction("取消", PopItemAction.PopItemStyle.Warning))
                .setPopWindowMarginsF(DeviceUtils.dip2px4View(getApplicationContext(),30), DeviceUtils.dip2px4View(getApplicationContext(),200), DeviceUtils.dip2px4View(getApplicationContext(),30), DeviceUtils.dip2px4View(getApplicationContext(),0))
                .show();
    }

    private void initProject(){
        equipmentList = equipmentUtil.queryEquipmentByLineIdAndNoSelf(lineId,equipmentId);
        List<String> projName = new ArrayList<>();
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,500);
        List<Equipment> list = equipmentList;
        ListView listView = new ListView(getApplicationContext());
        listView.setLayoutParams(layoutParams);
        for(Equipment equipment:list){
            projName.add(equipment.getName());
        }
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if(equipmentList.get(i).getId().equals(equipmentId)){
                    Toasty.error(getApplicationContext(), "不能选择当前设备", Toast.LENGTH_LONG, true).show();
                }else{
                    selectE = i;
                    clickEquipmentId = equipmentList.get(i).getId();
                    qssbView.setText(equipmentList.get(i).getName());
                    popupWindow.dismiss();
                }
            }
        });
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                getApplicationContext(), android.R.layout.simple_list_item_1, projName);
        listView.setAdapter(adapter);
        popupWindow= new PopWindow.Builder(EquipmentActivity.this)
                .setStyle(PopWindow.PopWindowStyle.PopAlert)
                .setMessage("请选择前端设备")
                .addContentView(listView)
                .setIsShowCircleBackground(false)
                .addItemAction(new PopItemAction("取消", PopItemAction.PopItemStyle.Warning))
                .setPopWindowMarginsF(DeviceUtils.dip2px4View(getApplicationContext(),30), DeviceUtils.dip2px4View(getApplicationContext(),200), DeviceUtils.dip2px4View(getApplicationContext(),30), DeviceUtils.dip2px4View(getApplicationContext(),0))
                .show();

    }
    @Override
    public void onRightClick(View v) {
        new PopWindow.Builder(EquipmentActivity.this)
                .setStyle(PopWindow.PopWindowStyle.PopUp)
                .setTitle("你确定要删除当前数据！！")
                .addItemAction(new PopItemAction("确定", PopItemAction.PopItemStyle.Warning, new PopItemAction.OnClickListener() {
                    @Override
                    public void onClick() {
                        clearEquipment();
                    }
                }))
                .addItemAction(new PopItemAction("取消", PopItemAction.PopItemStyle.Cancel))
                .show();
    }

    private void clearEquipment(){
        List<EquipmentLine> equipmentLineList = equipmentLineUtil.queryEquipmentLineByEid(equipmentId);
        for(EquipmentLine equipmentLine:equipmentLineList){
            equipmentLineUtil.deleteEquipmentLine(equipmentLine);
        }
        List<Equipment> equipmentList = equipmentUtil.queryEquipmentByLineIdPds(equipmentId);
        for(Equipment equipment:equipmentList){
            equipmentUtil.deleteEquipment(equipment);
        }
        equipmentUtil.deleteEquipment(equipmentUtil.listOneEquipment(equipmentId));
        this.finish();
    }


    private void showDataView(){
        List<Equipment> switchList = equipmentUtil.queryEquipmentByLineIdAndPDX(equipmentId);
        byqslView.setText(String.valueOf(switchList.size()));
        showData(switchList);
    }

    /**
     * 数据
     */
    private void showData(List<Equipment> titleData) {
        byqTable.setTableData(null);
        List<ByqInfo> byqInfos = new ArrayList<>();
        for (int i = 0; i < titleData.size(); i++) {
            final Equipment aSwitch = titleData.get(i);
            ByqInfo byqInfo = new ByqInfo();
            byqInfo.setId(aSwitch.getId());
            byqInfo.setXh(String.valueOf(i+1));
            byqInfo.setName(aSwitch.getName());
            byqInfo.setZt("正常");
            byqInfos.add(byqInfo);
        }


        if(byqInfos.size()>0){
            byqTable.setVisibility(View.VISIBLE);
            byqTable.setData(byqInfos);
            byqTable.getTableData().setOnRowClickListener(new TableData.OnRowClickListener() {
                @Override
                public void onClick(Column column, Object o, int col, int row) {
                    new PopWindow.Builder(EquipmentActivity.this)
                            .setStyle(PopWindow.PopWindowStyle.PopUp)
                            .setTitle("请选择你要的操作")
                            .addItemAction(new PopItemAction("查看详情", PopItemAction.PopItemStyle.Normal, new PopItemAction.OnClickListener(){
                                @Override
                                public void onClick() {
                                    Intent intent = new Intent(EquipmentActivity.this,EquipmentActivity.class);
                                    intent.putExtra("equipmentId",titleData.get(row).getId());
                                    startActivity(intent);
                                }
                            }))
                            .addItemAction(new PopItemAction("删除变压器", PopItemAction.PopItemStyle.Warning, new PopItemAction.OnClickListener() {
                                @Override
                                public void onClick() {
                                    deleteDataKg(titleData.get(row));
                                }
                            }))
                            .addItemAction(new PopItemAction("取消", PopItemAction.PopItemStyle.Cancel))
                            .show();
                }
            });
        }else{
            byqTable.setVisibility(View.GONE);
        }
    }

    private void deleteDataKg(Equipment s){
        new PopWindow.Builder(this)
                .setStyle(PopWindow.PopWindowStyle.PopUp)
                .setTitle("你确定要删除当前数据！！")
                .addItemAction(new PopItemAction("确定", PopItemAction.PopItemStyle.Warning, new PopItemAction.OnClickListener() {
                    @Override
                    public void onClick() {
                        equipmentUtil.deleteEquipment(s);
                        showDataView();


                    }
                }))
                .addItemAction(new PopItemAction("取消", PopItemAction.PopItemStyle.Cancel))
                .show();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(photoType.equals("qm")) {
            equipmentQmPhotoView.onActivityResultListener(requestCode, resultCode, data);
        }
        if(photoType.equals("mp")) {
            equipmentMpPhotoView.onActivityResultListener(requestCode, resultCode, data);
        }
        if(photoType.equals("gp")) {
            equipmentGpPhotoView.onActivityResultListener(requestCode, resultCode, data);
        }
        if(photoType.equals("qx")) {
            equipmentQxPhotoView.onActivityResultListener(requestCode, resultCode, data);
        }
        if(photoType.equals("tt")) {
            equipmentTtPhotoView.onActivityResultListener(requestCode, resultCode, data);
        }
        if(photoType.equals("gps")) {
            String nPath = Environment.getExternalStorageDirectory().getAbsolutePath()
                    + "/NZDAPP/Equipment/"+equipmentId+"/gps/";
            if(requestCode==100){
                List<String> files = Utils.getFilesAllName(nPath);
                if(files.size()==2){
                    new File(files.get(0)).delete();
                }
            }else{
                List<String> files = Utils.getFilesAllName(nPath);
                for(String path:files){
                    new File(path).delete();
                }
            }
            equipmentGpsPhotoView.onActivityResultListener(requestCode, resultCode, data);
            String xxPath = Environment.getExternalStorageDirectory().getAbsolutePath()
                    + "/NZDAPP/Equipment/"+equipmentId+"/gps/";
            List<String> xxfiles = Utils.getFilesAllName(xxPath);
            for(String path:xxfiles){
                getInfo(path);
            }
        }
        if(photoType.equals("zsq")) {
            equipmentZsqPhotoView.onActivityResultListener(requestCode, resultCode, data);
        }
        if(photoType.equals("blq")) {
            equipmentBlqPhotoView.onActivityResultListener(requestCode, resultCode, data);
        }
    }

    private void getInfo(String path) {
        try {
            ExifInterface exifInterface = new ExifInterface(path);

            String guangquan = exifInterface.getAttribute(ExifInterface.TAG_APERTURE);
            String shijain = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
            String baoguangshijian = exifInterface.getAttribute(ExifInterface.TAG_EXPOSURE_TIME);
            String jiaoju = exifInterface.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
            String chang = exifInterface.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);
            String kuan = exifInterface.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);
            String moshi = exifInterface.getAttribute(ExifInterface.TAG_MODEL);
            String zhizaoshang = exifInterface.getAttribute(ExifInterface.TAG_MAKE);
            String iso = exifInterface.getAttribute(ExifInterface.TAG_ISO);
            String jiaodu = exifInterface.getAttribute(ExifInterface.TAG_ORIENTATION);
            String baiph = exifInterface.getAttribute(ExifInterface.TAG_WHITE_BALANCE);
            String altitude_ref = exifInterface.getAttribute(ExifInterface
                    .TAG_GPS_ALTITUDE_REF);
            String altitude = exifInterface.getAttribute(ExifInterface.TAG_GPS_ALTITUDE);
            String latitude = exifInterface.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
            String latitude_ref = exifInterface.getAttribute(ExifInterface
                    .TAG_GPS_LATITUDE_REF);
            String longitude_ref = exifInterface.getAttribute(ExifInterface
                    .TAG_GPS_LONGITUDE_REF);
            String longitude = exifInterface.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
            String timestamp = exifInterface.getAttribute(ExifInterface.TAG_GPS_TIMESTAMP);
            String processing_method = exifInterface.getAttribute(ExifInterface
                    .TAG_GPS_PROCESSING_METHOD);

            //转换经纬度格式
            double lat = score2dimensionality(latitude);
            double lon = score2dimensionality(longitude);
            if(lat != 0.0 && lon!=0.0){
                latView.setText(String.valueOf(lat));
                lonView.setText(String.valueOf(lon));
            }

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("光圈 = " + guangquan+"\n")
                    .append("时间 = " + shijain+"\n")
                    .append("曝光时长 = " + baoguangshijian+"\n")
                    .append("焦距 = " + jiaoju+"\n")
                    .append("长 = " + chang+"\n")
                    .append("宽 = " + kuan+"\n")
                    .append("型号 = " + moshi+"\n")
                    .append("制造商 = " + zhizaoshang+"\n")
                    .append("ISO = " + iso+"\n")
                    .append("角度 = " + jiaodu+"\n")
                    .append("白平衡 = " + baiph+"\n")
                    .append("海拔高度 = " + altitude_ref+"\n")
                    .append("GPS参考高度 = " + altitude+"\n")
                    .append("GPS时间戳 = " + timestamp+"\n")
                    .append("GPS定位类型 = " + processing_method+"\n")
                    .append("GPS参考经度 = " + latitude_ref+"\n")
                    .append("GPS参考纬度 = " + longitude_ref+"\n")
                    .append("GPS经度 = " + lat+"\n")
                    .append("GPS经度 = " + lon+"\n");

            //将获取的到的信息设置到TextView上
            System.err.println(stringBuilder.toString());

            /**
             * 将wgs坐标转换成百度坐标
             * 就可以用这个坐标通过百度SDK 去获取该经纬度的地址描述
             */
//            double[] wgs2bd = GpsUtil.wgs2bd(lat, lon);


        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private double score2dimensionality(String string) {
        double dimensionality = 0.0;
        if (null==string){
            return dimensionality;
        }

        //用 ，将数值分成3份
        String[] split = string.split(",");
        for (int i = 0; i < split.length; i++) {

            String[] s = split[i].split("/");
            //用112/1得到度分秒数值
            double v = Double.parseDouble(s[0]) / Double.parseDouble(s[1]);
            //将分秒分别除以60和3600得到度，并将度分秒相加
            dimensionality=dimensionality+v/Math.pow(60,i);
        }
        return dimensionality;
    }

    @Override
    public void onClickPhotoListener(String type) {
        photoType = type;
    }

    @Override
    public void openPhotoView(String path) {
        Intent intent = new Intent(EquipmentActivity.this,PhotoDetailActivity.class);
        intent.putExtra("filePath",path);
        startActivity(intent);
    }

    private void openMenu(View view, List<OptionMenu> optionMenus, ClearEditText contentView){
        PopupMenuView menuView = new PopupMenuView(getApplicationContext());
        menuView.setMenuItems(optionMenus);
        menuView.setOrientation(LinearLayout.VERTICAL);
        menuView.setOnMenuClickListener(new OptionMenuView.OnOptionMenuClickListener() {
            @Override
            public boolean onOptionMenuClick(int position, OptionMenu menu) {
                contentView.setText(menu.getTitleRes());
                return true;
            }
        });

        menuView.show(view);
    }
    @Override
    public void onClick(View view) {
        if(view == qxxxRight){
            openMenu(qxxxRight, Arrays.asList(new OptionMenu(R.string.qxxx_1),new OptionMenu(R.string.qxxx_2),new OptionMenu(R.string.qxxx_3),
                    new OptionMenu(R.string.qxxx_5),new OptionMenu(R.string.qxxx_6),new OptionMenu(R.string.qxxx_7),
                    new OptionMenu(R.string.qxxx_8),new OptionMenu(R.string.qxxx_9),new OptionMenu(R.string.qxxx_10),
                    new OptionMenu(R.string.qxxx_11),new OptionMenu(R.string.qxxx_12),new OptionMenu(R.string.qxxx_13),
                    new OptionMenu(R.string.qxxx_14),new OptionMenu(R.string.qxxx_15),new OptionMenu(R.string.qxxx_16),new OptionMenu(R.string.qxxx_17)),qxxxView);
        }
        if(view==qdsbRight){
            initProject();
        }
        if(view == ssgtRight){
            initGT();
        }
        if(view == saveEquipmentView){
            saveData();
        }
        if(view == addbyq){
            newByq(Integer.valueOf(byqslView.getText().toString()));
        }

    }
}